# -*- coding: utf-8 -*-
import multiprocessing
import time
import progressbar


bar = progressbar.ProgressBar(max_value=100)


def do_one_page(data):
    global bar
    _, lock, counter = data
    with lock:
        counter.value += 1
    bar.update(counter.value)
    time.sleep(0.1)


if __name__ == '__main__':
    multiprocessing.freeze_support()
    pool = multiprocessing.Pool(max(multiprocessing.cpu_count() - 1, 1))
    manager = multiprocessing.Manager()

    counter = manager.Value('i', 0)
    lock = manager.Lock()
    inputs = [(i, lock, counter) for i in range(100)]
    pool.map(do_one_page, inputs)
    pool.close()
    pool.join()
